export function interval(str: string) {
  interface Time {
    d?: number;
    h?: number;
    m?: number;
    s?: number;
  }

  const result = str.split(" ");
  const res = result.reduce((pre, cur) => {
    const unit = cur.slice(-1);
    const num = cur.slice(0, -1);
    return {
      [unit]: num,
      ...pre,
    };
  }, {} as Time);

  return getDay() + getHour() +
    getMinute() + getSecond();

  function getUnitTime() {
    const oneSecond = 1000;
    const oneMinute = 60 * oneSecond;
    const oneHour = 60 * oneMinute;
    const oneDay = 24 * oneHour;
    return { oneSecond, oneMinute, oneHour, oneDay };
  }

  function getDay() {
    const { oneDay } = getUnitTime();
    return (res?.d || 0) * oneDay;
  }

  function getHour() {
    const { oneHour } = getUnitTime();
    return (res?.h || 0) * oneHour;
  }

  function getMinute() {
    const { oneMinute } = getUnitTime();
    return (res?.m || 0) * oneMinute;
  }

  function getSecond() {
    const { oneSecond } = getUnitTime();
    return (res?.s || 0) * oneSecond;
  }
}
